package group2.beans;

import group2.core.database.IJpaCtrl;
import group2.core.database.JpaCtrlFactory;
import group2.core.entities.CamelUser;
import group2.core.entities.Post;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 * Bean for managing which post we're about to view.
 * @author ludwig
 */
@ManagedBean
@ViewScoped
public class ShowPostViewBean implements Serializable{

    private long id;
    private Post post;
    private CamelUser user = null;

    public CamelUser getUser() {
        return user;
    }

    public void setUser(CamelUser user) {
        this.user = user;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        IJpaCtrl<Post> postCtrl = JpaCtrlFactory.getInstance().getPostCtrl();
        this.id = id;
        setPost(postCtrl.findEntity(id));
        
    }

    public Post getPost() {
        return post;
    }

    public void setPost(Post post) {
        this.post = post;
    }
    /** Creates a new instance of ShowPostViewBean */
    public ShowPostViewBean() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session =
                (HttpSession) context.getExternalContext().getSession(true);
        user = (CamelUser) session.getAttribute("username");
        
    }
}
